<?php
	require_once './Tool/DB/SqlDBManager.class.php';
	$sqlDBManager = new SqlDBManager();
	
	$date = $_SESSION['selectedBackDate'];
	
    $sql = "SELECT attendancerecord.NRIC, client.CustomerName, centre.CentreName, 
        attendancerecord.SignInTimeStamp, attendancerecord.SignOutTimeStamp, 
        attendancerecord.Status 
        FROM attendancerecord, client, centre 
        WHERE DATE(SignInTimeStamp)=? 
        AND attendancerecord.NRIC = client.NRIC 
        AND attendancerecord.CentreId = centre.CentreId ";

    $parameters=array($date);
	$res=$sqlDBManager->queryRows($sql,$parameters);
	
    echo "<table class='tablereport' id='tblAttendance' border='5'  valign='top'><tr >
	<th>Number</th>
	<th>NRIC</th>
	<th>Customer Name</th>
	<th>Centre Name</th>
	<th>Date</th>
	<th>Time In</th>
	<th>Time Out</th>
	<th>Status</th>
	</tr>";
    $count = 1;
    for($i=0;$i<count($res);$i++){
        echo"<tr>
		<td>" . $count . "</td>
		<td>" . $res[$i]['NRIC'] . "</td>
		<td>" . $res[$i]['CustomerName'] . "</td>
		<td>" . $res[$i]['CentreName'] . "</td>";
		$signin = strtotime($res[$i]['SignInTimeStamp']);
		$signintime = date('j F, Y', $signin);
		echo "<td >" . $signintime . "</td>";
		$signin = strtotime($res[$i]['SignInTimeStamp']);
		$signintime = date('H:i:s', $signin);
		echo"<td >" . $signintime . "</td>";
		if ($res[$i]['SignOutTimeStamp'] == '0000-00-00 00:00:00'){
			echo "<td ></td>
				<td><form method='POST'><input class='signoutbutton' id='signout" . $count . "'type='submit' name='signout" . $count . "'value='Sign Out' size='10' maxlength='9' align='center' onClick='this.style.display = 'none';signoutattendance(this.id)'/></form></td>";
		}else{
			$signout = strtotime($res[$i]['SignOutTimeStamp']);
			$signouttime = date('H:i:s', $signout);
			echo"<td >" . $signouttime . "</td>
				<td>" . $res[$i]['Status'] . "</td >";
			} 
		echo"</tr>";
		$count++;
    }
    echo "</table>";
    $count--;
    echo "Total number of elderly attended: " . $count . ".";

?>